import { request } from '@@/plugin-request/request';
import { transformParams, transformProTableData } from '@/utils/utils';
import type { HostInfoEntity } from '@/pages/HostInfo/service';

// 主机信息
export declare type NmapVoField =
  | 'ip' // IP 地址
  | 'mac' // MAC 地址
  | 'name' // 设备名称
  | 'status' // 设备状态
  | 'hostInfo'; // 系统中已经存在的信息
export type NmapVo = {
  // String IP 地址
  ip?: string;
  // String MAC 地址
  mac?: string;
  // String 设备名称
  name?: string;
  // String 设备状态
  status?: number;
  // 系统中已经存在的信息
  hostInfo?: HostInfoEntity;
  [key: string]: any;
};

const apiUri = '/wake-on-lan-server/lan-scan/';

export async function listNmap(
  params?: API.PageParams,
  sorter?: Record<string, any>,
  filter?: Record<string, any>,
) {
  return request<Struct.PageResponse<NmapVo>>(apiUri, {
    method: 'GET',
    params: transformParams(params, sorter, filter),
  }).then(transformProTableData);
}

export async function startNmapScan(data?: any) {
  return request(apiUri, { method: 'POST', data });
}

export async function stopNmapScan() {
  return request(apiUri, { method: 'DELETE' });
}

export async function scanIsDone() {
  return request(`${apiUri}isDone`, { method: 'GET' });
}
